package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	Id     int
	Name   string
	Gender string
	Sno    string
}

func main() {
	var a = &Student{
		Id:     0,
		Name:   "MiracleWong",
		Gender: "male",
		Sno:    "s001",
	}
	fmt.Println(a)
	data, err := json.Marshal(a)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(data))

	// 反序列化
	var str = `{"Id":0,"Name":"MiracleWong","Gender":"male","Sno":"s001"}`
	var s2 = &Student{}
	json.Unmarshal([]byte(str), s2)
	fmt.Printf("%T %#v\n", s2, s2)
}
